<template>
	<view class="page">
			<view class="courseware-list-box">
				<view v-for="(item,index) in pageList" :key="index" class="">
					<view class="time f_24 f_normal">{{item.createtime}}</view>
					<view class="info">
						<view class="dis-flex flex-y-center info-b-b">
							<view class="teacher-image p-r">
								<image v-if="userIdentity==0" :src="item.teacher!=null?item.teacher.headeravatar:imgPrefix('/static/image/icon/default_avatar.png')" mode="aspectFill" lazy-load></image>
								<image v-if="userIdentity==1" :src="item.user!=null?item.user.avatar:imgPrefix('/static/image/icon/default_avatar.png')" mode="aspectFill" lazy-load></image>
								<text v-if="userIdentity==0?item.reading==0:item.teacher_reading==0" class="reading dis-block p-a"></text>
							</view>
							<view class="navy_blue f_normal">
								<view class="f_32 teacher-name" v-if="userIdentity==0">{{item.course_order.language_grade}}{{item.course_order.language}}<text v-if="item.teacher!=null">{{item.teacher.nickname}}</text></view>
								<view class="f_24 gery1"  v-if="userIdentity==0">共计<text class="navy_blue">{{item.course_order.num}}</text>课次，<text class="navy_blue">{{item.course_order.total_hour}}</text>课时</view>
								<view class="f_32 teacher-name" v-if="userIdentity==1">
									<text @tap="bindCopy(item.user!=null?item.user.nickname:item.user.mobile)" >{{item.user!=null?item.user.nickname:item.user.mobile}}</text>
								</view>
								<view class="f_24 gery1"  v-if="userIdentity==1">第<text class="$violet1">{{item.course.index}}</text>次课程，共<text class="$violet1">{{item.course_order.num}}</text>次，剩余{{item.surplus}}次</view>
							</view>
						</view>
						<view class="btn-box f_24 f_normal flex-x-between dis-flex flex-y-center">
							<view class="f_28 navy_blue"><block v-if="item.type==1">
								{{item.time}}有课要上喔，请注意时间安排
							</block>
							<block v-else-if="item.type==2">
								课程已完成，进入详情页查看吧
							</block>
						<block v-else-if="item.type==3&&userIdentity==0">
								{{item.time}}已预约成功，请注意时间安排
							</block></view>
							<view class="btn onelist-hidden" @tap="bindToDetail(item.course_id,item.remind_course_id,userIdentity==0?item.reading:item.teacher_reading,index)">
								查看详情</view>
						</view>
					</view>
				</view>
			<load-more :status="loadingStatus" defaultIcon="1" text="暂无信息"></load-more>
			</view>
	</view>
</template>

<script>
import { commonMixinFun } from '@/static/mixins/common.js';
import API from '@/static/api/index.js';
import loadMore from '@/components/loadmore/index.vue';
const app = getApp();
export default{
	name:'course-to-remind',
	mixins: [commonMixinFun],
	components: {
		loadMore
	},
	data(){
		return{
			page:1,
			size:10,
			tools:0,
			isRequest:false,
			pageList:[],
			loadingStatus: 'loading'
		}
	},
	onShow(){
		this.getCourseList();
	},
	methods:{
		// 点击复制
		bindCopy(text) {
			uni.setClipboardData({
				data: text.toString(),
				success: res => {
					// this.showToast(text.toString()+'复制成功');
				},
				catch: err => {
					this.showToast('复制失败，请手动复制');
				}
			});
		},
		getCourseList(){
			let {page,size,isRequest,pageList,tools}=this;
			if(!isRequest&&(tools==0||tools>pageList.length)){
				this.isRequest=true
				let send = this.userIdentity==0? API.getCourseList({page:page,size:size}):API.getTeacherRemindCourse({page:page,size:size})
				send.then(res=>{
					app._log(res)
					if(res.code==1){
						let tempArr = (page==1?[]:pageList).concat(res.data.courses);
						this.pageList = tempArr
						this.page+=1
						this.loadingStatus = tempArr.length >= res.data.total ? 'nomore' : 'getmore';
					}else{
						if(res.code==405&&page==1){
						this.loadingStatus = 'empty';
						}else{
							this.loadingStatus = res.code == 405 ? (page == 1 ? 'empty' : 'nomore') : 'error';
							this.showToast(err.msg||'请稍后重试')
							if (num == 1) {
								this.pageList = [];
							}
						}
					}
					this.tools = res.data.total;
				}).finally(()=>{
					this.isRequest=false
				})
			}
		},
		bindToDetail(course_id,remind_course_id,reading,index){
			if(reading==0){
				let send = this.userIdentity==0?API.getCourseReading(remind_course_id):API.getTeacherCourseReading(remind_course_id)
				send.then(res=>{
					app._log(res)
					if(res.code==1){
						if(this.userIdentity==0){
							this.pageList[index].reading=1
						}else{
							this.pageList[index].teacher_reading=1
						}
					}
				})
			}
			this.pageTo(`/pages/${this.userIdentity==0?'course':'teacher/class_time'}_detail/index`,{course_id:course_id})
		}
	},
	onReachBottom(){
		console.log(123456)
		this.getCourseList();
	}
}
</script>

<style scoped lang="scss">

.courseware-list-box{
	.time{
		color: #999999;
		padding: 24rpx 0;
		text-align: center;
	}
	.info{
		background-color: white;
		margin: 0 48rpx 24rpx 48rpx;
		box-shadow: 0rpx 0rpx 16rpx 0rpx 
			rgba(37, 39, 72, 0.03);
		border-radius: 24rpx;
		.teacher-image{ 
			font-size: 0;
			image{
				width: 120rpx;
				height: 120rpx;
				border-radius: 16rpx;
				margin-right: 24rpx;
			}
		}
		.teacher-name{
			margin-bottom: 18rpx;
		}
		.info-b-b{
			margin: 0 24rpx;
			padding: 24rpx 0;
			border-bottom: 1px solid rgba(204, 204, 204, 0.5);
		}
		.btn-box{
			padding: 16rpx 24rpx;
			.btn{
				display: inline-block;
				background-image: linear-gradient(314deg, #7f4aff 0%, #9254ff 100%);
				border-radius: 16rpx;
				color: #ffffff;
				padding: 16rpx 32rpx;
			}
		}
	}
}
</style>
